package com.glela.controller;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSONObject;
import com.glela.cache.redis.RedisUtil;
import com.glela.common.constant.BaseConstants;

public abstract class ReportBaseController {
	protected static final DateTimeFormatter	DATE_TIME_YYYY_MM_DD_FORMATTER	= DateTimeFormat.forPattern(BaseConstants.DATE_FORMAT_YYYY_MM_DD);
	private final Logger						logger							= LoggerFactory.getLogger(this.getClass());
	@Autowired
	private RedisUtil							redisUtil;

	public RedisUtil getRedisUtil() {
		return redisUtil;
	}

	public Logger getLogger() {
		return logger;
	}

	protected String resultError(String msg) {
		return result(false, msg);
	}

	protected String result(String msg) {
		return result(true, msg, null);
	}

	protected String result(boolean result, String msg) {
		return result(result, msg, null);
	}

	protected String result(boolean result, String msg, Object data) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("success", result);
		jsonObject.put("errorMsg", msg);
		jsonObject.put("data", data);
		return jsonObject.toJSONString();
	}
}
